﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
using ReportMobile.inc;

namespace ReportMobile.v2
{
    public partial class Feed_expire : System.Web.UI.Page
    {
        public DataSet ds = new DataSet();
        public DataTable dt = new DataTable();  //此处必须new Datatable，否则直接fill(dt)会报对象为Null错误
        public DataRow dr;
        public string urlArea, areaName, rowFilter, rmbTotal;
        public Common cmm = new Common();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["area"] == null)
                return;
            urlArea = Request.QueryString["area"];
            if (urlArea == "cyq"){
                areaName = "川渝区";
                rowFilter = "('猪料（非放养）','猪场料（非放养）','鸡料','鱼料','其它')";
            }else{
                areaName = "非川渝";
                rowFilter = "('北京','长春','昆明','西安','咸阳','武威','湖北')";
            }

            try
            {
                StringBuilder sqlOrder = new StringBuilder("execute Cqwh90Proc");
                sqlOrder.AppendFormat(" @sfDatetime = '{0}'",DateTime.Now);
                dt = cmm.ExecuteProcedure(sqlOrder.ToString());
                dt.DefaultView.RowFilter = "公司简称 in " + rowFilter;  //根据不同区域，过滤
                dt.DefaultView.Sort = "欠款余额 DESC";  //对table排序
                
                dt = dt.DefaultView.ToTable();  //按排序后的记录生成新的table，并赋值给dt（否则没有任何变化）
                rmbTotal = string.Format("{0:N}", dt.Compute("sum(到期未还)", ""));
                ds.Tables.Add(dt);  //将表格（修改后）以默认别名的方式添加到ds中
                CqwhRpt.DataSource = ds;    //为repeater指定数据来源为 dataset
                CqwhRpt.DataBind(); //绑定生效
            }
            catch (Exception error)
            {
                Response.Write(error.Message);
            }
        }
    }
}